GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9eee63...dbdc9f )
by Florian
01:11
created

map.js ➔ ... ➔ parseLinesFromUrl.map   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $, google, Lines, Markers, Conversion, Cookies, Coordinates, trackMarker, mytrans, showAlert,
7
  id2alpha, alpha2id,
8
  showProjectionDialog, showLinkDialog,
9
  osmProvider, osmDeProvider, thunderforestProvider, opentopomapProvider,
10
  get_cookie_int, get_cookie_float, get_cookie_string,
11
  Attribution, Sidebar, ExternalLinks, Hillshading, Geolocation, NPA, CDDA, Freifunk, Okapi,
12
  DownloadGPX, API_KEY_THUNDERFOREST,
13
  restoreCoordinatesFormat,
14
  document
15
*/
16
17
//var boundariesLayer = null;
18
//var boundariesLayerShown = false;
19
var map = null;
20
var CLAT_DEFAULT = 51.163375;
21
var CLON_DEFAULT = 10.447683;
22
var ZOOM_DEFAULT = 12;
23
var MAPTYPE_DEFAULT = "OSM";
24
25
function projectFromMarker(id) {
26
    'use strict';
27
28
    trackMarker('project');
29
30
    var mm = Markers.getById(id),
31
        oldpos = mm.getPosition();
32
33
    showProjectionDialog(
34
        function (data1, data2) {
35
            var angle = Conversion.getFloat(data1, 0, 360),
36
                dist = Conversion.getFloat(data2, 0, 100000000000),
37
                newpos,
38
                newmarker;
39
40
            if (angle === null) {
41
                showAlert(
42
                    mytrans("dialog.error"),
43
                    mytrans("dialog.projection.error_bad_bearing").replace(/%1/, data1)
44
                );
45
                return;
46
            }
47
48
            if (dist === null) {
49
                showAlert(
50
                    mytrans("dialog.error"),
51
                    mytrans("dialog.projection.error_bad_distance").replace(/%1/, data2)
52
                );
53
                return;
54
            }
55
56
            newpos = Coordinates.projection_geodesic(oldpos, angle, dist);
57
            newmarker = Markers.newMarker(newpos, -1, 0, null);
58
            if (newmarker) {
59
                showAlert(
60
                    mytrans("dialog.information"),
61
                    mytrans("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha())
62
                );
63
            }
64
        }
65
    );
66
}
67
68
69
function storeCenter() {
70
    'use strict';
71
72
    var c = map.getCenter();
73
    Cookies.set('clat', c.lat(), {expires: 30});
74
    Cookies.set('clon', c.lng(), {expires: 30});
75
}
76
77
78
function storeZoom() {
79
    'use strict';
80
81
    Cookies.set('zoom', map.getZoom(), {expires: 30});
82
}
83
84
85
function storeMapType() {
86
    'use strict';
87
88
    Cookies.set('maptype', map.getMapTypeId(), {expires: 30});
89
}
90
91
92
function getFeaturesString() {
93
    'use strict';
94
95
    var s = "";
96
    //if ($('#boundaries').is(':checked')) { s += "b"; }
97
    if ($('#geocaches').is(':checked')) { s += "g"; }
98
    if ($('#hillshading').is(':checked')) { s += "h"; }
99
    if ($('#npa').is(':checked')) { s += "n"; }
100
    if ($('#freifunk').is(':checked')) { s += "f"; }
101
102
    return s;
103
}
104
105
106
function getPermalink() {
107
    'use strict';
108
109
    var lat = map.getCenter().lat(),
110
        lng = map.getCenter().lng(),
111
        geocache = Okapi.popupCacheCode(),
112
        url = "https://flopp.net/" +
113
            "?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) +
114
            "&z=" + map.getZoom() +
115
            "&t=" + map.getMapTypeId() +
116
            "&f=" + getFeaturesString() +
117
            "&m=" + Markers.toString() +
118
            "&d=" + Lines.getLinesText();
119
    if (geocache) {
120
        url += "&g=" + geocache;
121
    }
122
    return url;
123
}
124
125
function generatePermalink() {
126
    'use strict';
127
128
    var link = getPermalink();
129
    showLinkDialog(link);
130
}
131
132
133
function repairLat(x, d) {
134
    'use strict';
135
136
    if (Coordinates.validLat(x)) {
137
        return x;
138
    }
139
140
    return d;
141
}
142
143
144
function repairLon(x, d) {
145
    'use strict';
146
147
    if (Coordinates.validLng(x)) {
148
        return x;
149
    }
150
151
    return d;
152
}
153
154
155
function repairRadius(x, d) {
156
    'use strict';
157
158
    if (x === null || isNaN(x) || x < 0 || x > 100000000) {
159
        return d;
160
    }
161
162
    return x;
163
}
164
165
166
function repairZoom(x, d) {
167
    'use strict';
168
169
    if (x === null || isNaN(x) || x < 1 || x > 20) {
170
        return d;
171
    }
172
173
    return x;
174
}
175
176
177
function repairMaptype(t, d) {
178
    'use strict';
179
180
    var mapTypes = {
181
        "OSM": 1, "OSM/DE": 1, "OCM": 1, "OUTD": 1, "TOPO": 1, "satellite": 1, "hybrid": 1, "roadmap": 1, "terrain": 1
182
    };
183
184
    if (mapTypes[t]) {
185
        return t;
186
    }
187
188
    return d;
189
}
190
191
192
function parseMarkersFromUrl(urlarg) {
193
    'use strict';
194
195
    if (urlarg === null) {
196
        return [];
197
    }
198
199
    var markers = [],
200
        data;
201
202
    // ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)?
203
    // COORDS=LAT:LON or DEG or DMMM
204
    if (urlarg.indexOf("*") >= 0) {
205
        data = urlarg.split('*');
206
    } else {
207
        /* sep is '|' */
208
        data = urlarg.split('|');
209
    }
210
211
    data.map(function (dataitem) {
212
        dataitem = dataitem.split(':');
213
        if (dataitem.length < 3 || dataitem.length > 5) {
214
            return;
215
        }
216
217
        var m = {
218
                alpha: dataitem[0],
219
                id: alpha2id(dataitem[0]),
220
                name: null,
221
                coords: null,
222
                r: 0
223
            },
224
            index = 1,
225
            lat,
226
            lon;
227
228
        if (m.id < 0) {
229
            return;
230
        }
231
232
        lat = parseFloat(dataitem[index]);
233
        lon = parseFloat(dataitem[index + 1]);
234
        if (Coordinates.valid(lat, lon)) {
235
            index += 2;
236
            m.coords = new google.maps.LatLng(lat, lon);
237
        } else {
238
            m.coords = Coordinates.fromString(dataitem[index]);
239
            index += 1;
240
        }
241
        if (!m.coords) {
242
            return;
243
        }
244
245
        m.r = repairRadius(parseFloat(dataitem[index]), 0);
246
        index = index + 1;
247
248
        if (index < dataitem.length &&
249
                /^([a-zA-Z0-9-_]*)$/.test(dataitem[index])) {
250
            m.name = dataitem[index];
251
        }
252
253
        markers.push(m);
254
    });
255
256
    return markers;
257
}
258
259
260
function parseCenterFromUrl(urlarg) {
261
    'use strict';
262
263
    if (urlarg === null) {
264
        return null;
265
    }
266
267
    var data = urlarg.split(':');
268
269
    if (data.length === 1) {
270
        return Coordinates.fromString(data[0]);
271
    }
272
273
    if (data.length === 2) {
274
        return Coordinates.toLatLng(parseFloat(data[0]), parseFloat(data[1]));
275
    }
276
277
    return null;
278
}
279
280
281
function parseLinesFromUrl(urlarg) {
282
    'use strict';
283
284
    if (urlarg === null) {
285
        return [];
286
    }
287
288
    var lines = [];
289
290
    /* be backwards compatible */
291
    if (urlarg.length === 3
292
            && alpha2id(urlarg[0]) >= 0
293
            && urlarg[1] === '*'
294
            && alpha2id(urlarg[1]) >= 0) {
295
        urlarg = urlarg[0] + ':' + urlarg[2];
296
    }
297
298
    urlarg.split('*').map(function (pair_string) {
299
        var pair = pair_string.split(':');
300
        if (pair.length === 2) {
301
            lines.push({source: alpha2id(pair[0]), target: alpha2id(pair[1])});
302
        }
303
304
    });
305
306
    return lines;
307
}
308
309
310
function parseMarkersFromCookies() {
311
    'use strict';
312
313
    var raw_ids = Cookies.get('markers'),
314
        markers = [];
315
316
    if (raw_ids === null || raw_ids === undefined) {
317
        return markers;
318
    }
319
320
    raw_ids.split(':').map(function (id_string) {
321
        var m = {id: null, name: null, coords: null, r: 0},
322
            raw_data,
323
            data;
324
325
        m.id = parseInt(id_string, 10);
326
        if (m.id === null || m.id < 0 || m.id >= 26 * 10) {
327
            return;
328
        }
329
330
        raw_data = Cookies.get('marker' + m.id);
331
        if (!raw_data) {
332
            return;
333
        }
334
335
        data = raw_data.split(':');
336
        if (data.length !== 4) {
337
            return;
338
        }
339
340
        m.coords = Coordinates.toLatLng(parseFloat(data[0]), parseFloat(data[1]));
341
        if (!m.coords) {
342
            return;
343
        }
344
345
        m.r = repairRadius(parseFloat(data[2]), 0);
346
347
        if (/^([a-zA-Z0-9-_]*)$/.test(data[3])) {
348
            m.name = data[3];
349
        }
350
351
        markers.push(m);
352
    });
353
354
    return markers;
355
}
356
357
358
function parseLinesFromCookies() {
359
    'use strict';
360
361
    var raw_lines = Cookies.get('lines'),
362
        lines = [];
363
364
    if (!raw_lines) {
365
        return lines;
366
    }
367
368
    raw_lines.split('*').map(function (pair_string) {
369
        var pair = pair_string.split(':');
370
        if (pair.length === 2) {
371
            lines.push({source: alpha2id(pair[0]), target: alpha2id(pair[1])});
372
        }
373
    });
374
375
    return lines;
376
}
377
378
379
function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) {
380
    'use strict';
381
382
    var center,
383
        atDefaultCenter = false,
384
        zoom = parseInt(xzoom, 10),
385
        maptype = xmap,
386
        loadfromcookies = false,
387
        markerdata = parseMarkersFromUrl(xmarkers),
388
        markercenter = null,
389
        clat = 0,
390
        clon = 0;
391
    if (markerdata.length > 0) {
392
        markerdata.map(function (m) {
393
            clat += m.coords.lat();
394
            clon += m.coords.lng();
395
        });
396
        markercenter = new google.maps.LatLng(clat / markerdata.length, clon / markerdata.length);
397
    }
398
399
    if (xcenter && xcenter !== '') {
400
        center = parseCenterFromUrl(xcenter);
401
    } else if (markercenter) {
402
        center = markercenter;
403
    } else {
404
        loadfromcookies = true;
405
406
        /* try to read coordinats from cookie */
407
        clat = get_cookie_float('clat', CLAT_DEFAULT);
408
        clon = get_cookie_float('clon', CLON_DEFAULT);
409
        if (clat === CLAT_DEFAULT && clon === CLON_DEFAULT) {
410
            atDefaultCenter = true;
411
        }
412
413
        clat = repairLat(clat, CLAT_DEFAULT);
414
        clon = repairLon(clon, CLON_DEFAULT);
415
        center = new google.maps.LatLng(clat, clon);
416
417
        zoom = get_cookie_int('zoom', ZOOM_DEFAULT);
418
        maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT);
419
    }
420
421
    if (!center) {
422
        center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT);
423
        atDefaultCenter = true;
424
    }
425
426
    zoom = repairZoom(zoom, ZOOM_DEFAULT);
427
    maptype = repairMaptype(maptype, MAPTYPE_DEFAULT);
428
    map = new google.maps.Map(
429
        document.getElementById("themap"),
430
        {
431
            zoom: zoom,
432
            center: center,
433
            scaleControl: true,
434
            streetViewControl: false,
435
            mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] },
436
            mapTypeId: google.maps.MapTypeId.ROADMAP
437
        }
438
    );
439
440
    map.mapTypes.set("OSM", osmProvider("OSM"));
441
    map.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE"));
442
    map.mapTypes.set("OCM", thunderforestProvider("OCM", "cycle", API_KEY_THUNDERFOREST));
443
    map.mapTypes.set("OUTD", thunderforestProvider("OUTD", "outdoors", API_KEY_THUNDERFOREST));
444
    map.mapTypes.set("TOPO", opentopomapProvider("TOPO"));
445
    map.setMapTypeId(maptype);
446
447
    Attribution.init(map);
448
    Sidebar.init(map);
449
    ExternalLinks.init(map);
450
    Markers.init(map);
451
    Lines.init(map);
452
    Geolocation.init(map);
453
    Hillshading.init(map);
454
    NPA.init(map);
455
    CDDA.init(map);
456
    Freifunk.init(map);
457
    Okapi.init(map);
458
    DownloadGPX.init(map);
459
460
    //boundariesLayer = new google.maps.ImageMapType({
461
    //  getTileUrl: function(coord, zoom) {
462
    //    if (6 <= zoom && zoom <= 16)
463
    //    {
464
    //      return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom);
465
    //    }
466
    //    else
467
    //    {
468
    //      return null;
469
    //    }
470
    //  },
471
    //  tileSize: new google.maps.Size(256, 256),
472
    //  name: "adminb",
473
    //  alt: "Administrative Boundaries",
474
    //  maxZoom: 16 });
475
476
    map.setCenter(center, zoom);
477
478
    google.maps.event.addListener(map, "center_changed", function () {
479
        storeZoom();
480
        storeCenter();
481
    });
482
    google.maps.event.addListener(map, "zoom_changed", function () {
483
        storeZoom();
484
        storeCenter();
485
    });
486
    google.maps.event.addListener(map, "maptypeid_changed", function () {
487
        storeMapType();
488
    });
489
490
    if (loadfromcookies) {
491
        parseMarkersFromCookies().map(function (m) {
492
            Markers.newMarker(m.coords, m.id, m.r, m.name);
493
        });
494
495
        parseLinesFromCookies().map(function (m) {
496
            Lines.newLine(m.source, m.target);
497
        });
498
    } else {
499
        markerdata.map(function (m) {
500
            Markers.newMarker(m.coords, m.id, m.r, m.name);
501
        });
502
503
        parseLinesFromUrl(xlines).map(function (m) {
504
            Lines.newLine(m.source, m.target);
505
        });
506
    }
507
508
    Okapi.setShowCache(xgeocache);
509
    Sidebar.restore(true);
510
    xfeatures = xfeatures.toLowerCase();
511
    if (xfeatures === '[default]') {
512
        Hillshading.restore(false);
513
        //restoreBoundaries(false);
514
        Okapi.restore(false);
515
        NPA.toggle(false);
516
        CDDA.toggle(false);
517
        Freifunk.toggle(false);
518
    } else {
519
        Hillshading.toggle(xfeatures.indexOf('h') >= 0);
520
        //toggleBoundaries(xfeatures.indexOf('b') >= 0);
521
        Okapi.toggle(xfeatures.indexOf('g') >= 0);
522
        NPA.toggle(xfeatures.indexOf('n') >= 0);
523
        Freifunk.toggle(xfeatures.indexOf('f') >= 0);
524
    }
525
    restoreCoordinatesFormat("DM");
526
527
    if (xgeocache !== "") {
528
        Okapi.toggle(true);
529
        atDefaultCenter = false;
530
    }
531
532
    Attribution.forceUpdate();
533
534
    if (atDefaultCenter) {
535
        Geolocation.whereAmI();
536
    }
537
}
538